package com.longge;

/**
 * @创建人 xinglongge
 * @创建时间 2021/7/19
 * @描述
 */
public class AddRungs {

    public int addRungs(int[] rungs, int dist) {

        int pre = 0, cur, res = 0;
        for (int rung : rungs) {
            cur = rung;
            int step = cur - pre;
            int x = step / dist;
            int y = step % dist;
            res += x - 1 + (y == 0 ? 0 : 1);
            pre=cur;
        }
        return res;
    }

    public static void main(String[] args) {
        new AddRungs().addRungs(new int[]{1, 3, 5, 10}, 2);
    }
}
